<template>
  <div>
    <a-table
      ref="table"
      size="middle"
      :scroll="{x:true}"
      bordered
      rowKey="teacherId"
      :columns="columns"
      :dataSource="dataSource"
      :pagination="ipagination"
      :loading="loading"
      class="j-table-force-nowrap"
      @change="handleTableChange">

      <span slot="action" slot-scope="text, record">
        <div>
          <a @click="handleDetail(record)">详情</a>
        </div>
      </span>

    </a-table>
    <a-drawer
      title="积分详情"
      placement="left"
      :closable="true"
      :visible="visible"
      @close="onClose"
      :destroyOnClose="true"
      width="95%"
    >
      <a-card>
        <TeacherCoreAssessmentResult :user-name="selectUsername" :query-date="date"></TeacherCoreAssessmentResult>
      </a-card>
    </a-drawer>
  </div>


</template>

<script>
import { getAction } from '@api/manage'
import TeacherDetail from '@views/gfxy/statistics/summary/TeacherDetail'
import TeacherCoreAssessmentResult
  from '@views/dashboard/gfxy/assessmentResult/coreAssessment/TeacherCoreAssessmentResult.vue'
export default {
  name: 'CoreSummaryForOrg',
  components: {
    TeacherCoreAssessmentResult,
    TeacherDetail,
  },
  props: {
    date:{
      type: String,
      required: false
    },
    orgCode:{
      type: String,
      required: false
    },
    scoreType:{
      type: Number,
      required: true
    }
  },
  watch:{
    date(){
      this.loadData();
    },
    orgCode(){
      this.ipagination.current = 1;
      // this.ipagination.pageSize;
      this.loadData();
    }
  },
  data(){
    return {
      columns:[

        {
          title:'教师姓名',
          align:"center",
          width:100,
          dataIndex: 'realname'
        },
        {
          title:'职称',
          align:"center",
          width:100,
          dataIndex: 'titleRank_dictText'
        },
        {
          title:'教师类型',
          align:"center",
          width:100,
          dataIndex: 'teacherType_dictText'
        },
        {
          title:'工作部门',
          align:"center",
          width:100,
          dataIndex: 'orgCode_dictText'
        },
        {
          title:'兼课学院',
          align:"center",
          width:100,
          dataIndex: 'teachingOrgCode_dictText'
        },
        {
          title:'教学建设',
          align:"center",
          width:100,
          dataIndex: 'teachingBuild'
        },
        {
          title:'学生大赛',
          align:"center",
          width:100,
          dataIndex: 'studentMatch'
        },
        {
          title:'科学研究与社会服务',
          align:"center",
          width:100,
          dataIndex: 'research'
        },
        {
          title:'基层党建与学生管理',
          align:"center",
          width:100,
          dataIndex: 'studentManage'
        },
        {
          title: '总分',
          align:"center",
          width:100,
          dataIndex: 'totalScore'
        },
        {
          title: '操作',
          dataIndex: 'action',
          align:"center",
          fixed:"right",
          width:147,
          scopedSlots: { customRender: 'action' }
        }
      ],
      ipagination:{
        current: 1,
        pageSize: 15,
        pageSizeOptions: ['10', '20', '30'],
        showTotal: (total, range) => {
          return range[0] + "-" + range[1] + " 共" + total + "条"
        },
        showQuickJumper: true,
        showSizeChanger: true,
        total: 0
      },
      loading:false,
      dataSource:[],
      url:{
        list: 'statistics/coreSummary/listSummaryForOrg',

      },
      visible:false,
      selectUsername:''
    }
  },
  methods:{
    handleTableChange(pagination, filters, sorter) {
      //分页、排序、筛选变化时触发
      //TODO 筛选
      console.log(pagination)
      if (Object.keys(sorter).length > 0) {
        this.isorter.column = sorter.field;
        this.isorter.order = "ascend" == sorter.order ? "asc" : "desc"
      }
      this.ipagination = pagination;
      this.loadData();
    },
    loadData(){
      if(!this.url.list){
        this.$message.error("请设置url.list属性!")
        return
      }
      let params = {date:this.date, orgCode:this.orgCode,pageNo:this.ipagination.current,pageSize:this.ipagination.pageSize}
      this.loading = true;
      getAction(this.url.list, params).then((res) => {
        console.log(res)
        if (res.success) {
          this.dataSource = res.result.records||res.result;
          if(res.result.total)
          {
            this.ipagination.total = res.result.total;
          }else{
            this.ipagination.total = 0;
          }
        }
        if(res.code===510){
          this.$message.warning(res.message)
        }
        this.loading = false;
      })
    },
    handleDetail:function(record){
      console.log(record)
      this.selectUsername = record.teacherId;
      this.visible = true;
    },

    onClose() {
      this.visible = false;
    },

  },
  created() {
    this.loadData();
  }
}
</script>

<style scoped>
@import '~@assets/less/common.less';
</style>